package demo2;


class MyCircularQueue {
    public int[] elem;
    public int front; //队头下标
    public int rear; // 队尾下标

    public MyCircularQueue (int k) {
        this.elem = new int[k + 1];
    }
    //获得队首元素
    public int Front () {
        if (isEmpty()) {
            return -1;
        }
        return elem[front];
    }

    //获得队尾元素
    public int Rear () {
        if (isEmpty()) {
            return -1;
        }
        if (rear == 0) {
            return elem[elem.length-1];
        } else {
            return elem[rear - 1];
        }
    }

    //插入元素
    public boolean enQueue (int value) {
        if (isFull()) {
            return false;
        }
        elem[rear] = value;
        rear = (rear + 1) % elem.length;
        return true;
    }
    //删除元素
    public  boolean deQueue () {
        if (isEmpty()) {
            return false;
        }
        front = (front + 1) % this.elem.length;
        return true;
    }
    public boolean isEmpty () {
        return rear == front;
    }
    public boolean isFull () {
        return (rear + 1) % elem.length == front;
    }
}






public class Test2 {
}
